/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Alberto, Alessandra
 */
@Entity
@IdClass(InvitationPK.class)
@NamedQueries({
    @NamedQuery(
            name = "findByEvent",
            query = "SELECT i FROM Invitation i WHERE i.event = :Ievent"
        ),
    @NamedQuery(
            name = "findByUser",
            query = "SELECT i FROM Invitation i WHERE i.user = :Iuser"
        ),
    @NamedQuery(
            name = "findById",
            query = "SELECT i FROM Invitation i WHERE i.user = :Iuser AND i.event = :Ievent"
        ),
    @NamedQuery(
            name = "findByUserNew",
            query = "SELECT i FROM Invitation i WHERE i.user = :Iuser AND i.visualized = FALSE"
        )
})
public class Invitation implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @ManyToOne
    @JoinColumn(name = "iduser", referencedColumnName = "id")
    private User user;
    
    @Id
    @ManyToOne
    @JoinColumn(name = "idevent", referencedColumnName = "id")
    private Event event;
    
    @NotNull(message = "May not be empty")
    private Boolean replied;
    
    @NotNull(message = "May not be empty")
    private Boolean visualized;
    
    public Invitation () {
        
    }
    
    public Invitation (User user, Event event) {
        this.event = event;
        this.user = user;
        this.visualized = false;
        this.replied = false;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public Boolean getReplied() {
        return replied;
    }

    public void setReplied(Boolean replied) {
        this.replied = replied;
    }

    public Boolean getVisualized() {
        return visualized;
    }

    public void setVisualized(Boolean visualized) {
        this.visualized = visualized;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Invitation other = (Invitation) obj;
        if (!Objects.equals(this.user, other.user)) {
            return false;
        }
        if (!Objects.equals(this.event, other.event)) {
            return false;
        }
        return true;
    }
    
}
